$(function(){
    addTabOne(1);
    addTabtwo(1);
    //放置tzb1的数据
    function addTabOne(pageNo) {
        var params = {'courseId' :courseId};
        params = JSON.stringify(params);
        var obj = {
            url: baseloaction + '/admin/course/profile/ajaxCatalogProfileDetailList',//请求URL
            contextId: 'oc-ibox-content',//响应内容页面设置内容ID
            params: params,//请求参数
            pageNo: pageNo,//页码
            pageCall: addTabOne, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            selectAllId: 'all-select',        //全选框ID
            callback : function() {
                $('#total').html(total);
            }
        };
        ajaxGetListData(obj);
    }


    //放置tzb2的数据
    function addTabtwo(pageNo) {
        $.ajax({
            url:baseloaction + '/admin/course/profile/courseCatalogProfileDetail?courseId='+courseId,
            dataType:"html",
            type:'get',
            success:function(result){
                $('#oto-ibox-content').html(result);
            }

        })
    }


    $(document).on('click','.refresh',function(){//监听tab切换
       $('#refresh').data('tab', $(this).data('value'));
    }).on('click','#refresh',function(){//监听页面刷新按钮
        switch ($(this).data('tab')) {
            case 1:
                addTabOne(1);
                break;
            case 2:
                 addTabtwo(1);
             break;
        }
    }).on('click','#downloadExcel',function(){
        var type =null;
        switch ($('#refresh').data('tab')) {
            case 1:
                type="evaluationDetails";
                break;
            case 2:
                type ="evaluation";
                break;
        }
        var commentIds = getIsCheckbox();
        var params = 'commentIds=' + commentIds+"&type="+type;
        if(type=="evaluation"){
            params+=  '&id=' + courseId
          window.open(baseloaction + '/admin/course/profile/downloadExcelDetailList?' + params, '_blank');
        }else{
            params+=  '&courseId=' + courseId
            exportExecl.init({
                    title:"导出章节评价明细",
                    excelUrl: '/admin/course/profile/downloadExcelDetailList?' + params,
                    type:7
                }
            )
        }
    }).on('click', 'i.fa-eye', function () { // 显示单个节点的评价内容列表
        var id =$(this).parent('a').data('id');
        parent.layer.open({
            type: 2,
            shadeClose: false,
            shade: [0.3, '#000000'],
            title: '<strong>章节评价明细</strong>',
            area: winArea,
            content: baseloaction + "/admin/course/profile/catalogProfileDetailList?catalogId="+id,
            btn: ['关闭'],
            yes: function (index, layero) {
                parent.layer.close(index);
            }
        });
    }).on('click','i.fa-unlock-alt,i.fa-history',function () {//隐藏和显示
        var _this = $(this);
        var id = _this.parent().data('id');
        var status = _this.parent().data('status');
        updateCourseCommentStatus(id,status,function () {
            var context = '';
            if(status==1){
                context = '<span class="label label-info">显示</span>';
                _this.addClass('fa-unlock-alt').removeClass('fa-history');
                _this.parent().attr('data-status','2');
                _this.parent().data('status',2);
            }else if(status==2){
                context = '<span class="label label-default">隐藏</span>';
                _this.addClass('fa-history').removeClass('fa-unlock-alt');
                _this.parent().attr('data-status','1');
                _this.parent().data('status',1);
            }
            $("#status-"+id).html(context);
        });
    });

    function getIsCheckbox(){
        var checked = $('input[type=checkbox]:checked');
        var ids = checked.map(function () {
            return this.value;
        }).get().join(',');
        return ids;
    };
});